package com.itheima.controller;

import com.itheima.pojo.dto.IntegralDTO;
import com.itheima.pojo.Student;
import com.itheima.service.UserService;
import com.itheima.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/findByClassId")
    public ResponseResult findByClassId() {
        List<Student> students = userService.findAll();
        return new ResponseResult(0, "操作成功", students);
    }

    @PostMapping("/addIntegral")
    public ResponseResult addIntegral(@RequestBody IntegralDTO integralDTO) {
        boolean flag = userService.addIntegral(integralDTO);
        if (flag) {
            return new ResponseResult(0,"操作成功","");
        }else {
            return new ResponseResult(1,"操作失败","");
        }
    }

    @GetMapping("/resetGScoreByGroupId/{classId}")
    public ResponseResult updateGroupsIntegralByClassId(@PathVariable Integer classId) {
        boolean flag = userService.updateGroupsIntegralByClassId(classId);
        if (flag) {
            return new ResponseResult(0,"操作成功","重置成功");
        }else {
            return new ResponseResult(1,"操作失败","重置失败");
        }
    }

}
